package com.cn.service;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

@Service
public class ThreadService {
    @Resource
    Executor asyncExecutor;

    /**
     * 线程处理
     * @param integers
     * @return
     */
    public CompletableFuture<List<Integer>> dealNums(List<Integer> integers){
        return CompletableFuture.supplyAsync(()->{
            for (Integer i:integers){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(i);
            }
            return integers;
        },asyncExecutor);
    }

}
